# Copyright 2024 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load(
    "//build_tools/bazel:build_defs.oss.bzl",
    "iree_compiler_cc_library",
    "iree_gentbl_cc_library",
    "iree_tablegen_doc",
)

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_compiler_cc_library(
    name = "DispatchCreation",
    srcs = [
        "AnnotateDataTilingHints.cpp",
        "BitcastUnsupportedElementTypes.cpp",
        "BubbleUpExpandShapes.cpp",
        "CloneProducersIntoDispatchRegions.cpp",
        "CollapseDimensions.cpp",
        "ConvertDispatchRegionsToWorkgroups.cpp",
        "ConvertEncodingToFlow.cpp",
        "ConvertTensorToFlow.cpp",
        "ElementwiseOpFusion.cpp",
        "FoldReshapesIntoTensorBarriers.cpp",
        "FoldUnitExtentDims.cpp",
        "FormDispatchRegions.cpp",
        "FormScalarDispatches.cpp",
        "FormSplitReductionDispatches.cpp",
        "FuseEncodingOpsIntoDispatchRegions.cpp",
        "FuseHorizontalContractions.cpp",
        "FuseMultiUseElementwiseProducer.cpp",
        "FusionPreprocessing.cpp",
        "FusionUtils.cpp",
        "HoistEncodingOps.cpp",
        "HoistUniformScalarCompute.cpp",
        "InsertTensorBarriers.cpp",
        "MaterializeDefaultWorkgroupCountRegion.cpp",
        "Passes.cpp",
        "PropagateEncodings.cpp",
        "RemoveTensorBarriers.cpp",
        "SetEncoding.cpp",
        "SetSplitReductionSizes.cpp",
        "SinkReshapes.cpp",
        "SplitReduction.cpp",
        "TensorPadToTensorInsertSlice.cpp",
        "TransposeGenericOps.cpp",
    ],
    hdrs = [
        "FusionUtils.h",
        "Passes.h",
    ],
    deps = [
        ":PassHeaders",
        ":PassesIncGen",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Dialect/Encoding/IR",
        "//compiler/src/iree/compiler/Dialect/Encoding/Utils",
        "//compiler/src/iree/compiler/Dialect/Flow/Conversion/TensorToFlow",
        "//compiler/src/iree/compiler/Dialect/Flow/IR",
        "//compiler/src/iree/compiler/Dialect/Flow/Transforms",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/Transforms",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/Utils",
        "//compiler/src/iree/compiler/Dialect/Stream/IR",
        "//compiler/src/iree/compiler/Dialect/TensorExt/IR",
        "//compiler/src/iree/compiler/Dialect/TensorExt/Transforms",
        "//compiler/src/iree/compiler/Dialect/Util/Analysis",
        "//compiler/src/iree/compiler/Dialect/Util/Analysis/Attributes",
        "//compiler/src/iree/compiler/Dialect/Util/Analysis/Constant",
        "//compiler/src/iree/compiler/Dialect/Util/Analysis/DFX",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "//compiler/src/iree/compiler/Dialect/Util/Transforms",
        "//compiler/src/iree/compiler/Pipelines:Options",
        "//compiler/src/iree/compiler/Utils",
        "//llvm-external-projects/iree-dialects:IREEDialectsTransforms",
        "//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:AffineUtils",
        "@llvm-project//mlir:Analysis",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:ControlFlowDialect",
        "@llvm-project//mlir:DestinationStyleOpInterface",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:LinalgUtils",
        "@llvm-project//mlir:MathDialect",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:MemRefTransforms",
        "@llvm-project//mlir:PDLDialect",
        "@llvm-project//mlir:PDLInterpDialect",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFTransforms",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TensorTransforms",
        "@llvm-project//mlir:TensorUtils",
        "@llvm-project//mlir:TilingInterface",
        "@llvm-project//mlir:TransformDialect",
        "@llvm-project//mlir:TransformDialectTransforms",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

iree_gentbl_cc_library(
    name = "PassesIncGen",
    tbl_outs = [
        (
            ["--gen-pass-decls"],
            "Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "PassHeaders",
    hdrs = [
        "Passes.h",
        "Passes.h.inc",
    ],
    deps = [
        ":PassesIncGen",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

iree_tablegen_doc(
    name = "DispatchCreationPassesDocGen",
    category = "Passes",
    tbl_outs = [
        (
            [
                "--gen-pass-doc",
            ],
            "DispatchCreationPasses.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)
